//
//  ShenPiJiLuListTableViewCell.m
//  JuBoCRM
//
//  Created by iMac on 2024/2/22.
//  Copyright © 2024 iningKe. All rights reserved.
//

#import "ShenPiJiLuListTableViewCell.h"
#import "UILabel+YBAttributeTextTapAction.h"
@implementation ShenPiJiLuListTableViewCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code

    
}

- (void)setModel:(AllModel *)model{
    _model = model;
    NSDictionary *dataDic = model.modelInfoDictionary;
    self.titleLabel.text = GetHandleString(dataDic, @"categoryTitle");
    self.contentLabel.text = GetHandleString(dataDic, @"content");
    self.timeLabel.text = GetHandleString(dataDic, @"createTime");
    if([GetHandleString(dataDic, @"examineStatus") integerValue] == 0){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"待审核";
        self.statusView1.backgroundColor = rgba(255, 248, 235, 1);
        self.statusView2.backgroundColor = rgba(196, 142, 34, 1);
        self.statusLabel.textColor = rgba(196, 142, 34, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 1){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"通过";
        self.statusView1.backgroundColor = rgba(232, 255, 239, 1);
        self.statusView2.backgroundColor = rgba(51, 196, 34, 1);
        self.statusLabel.textColor = rgba(51, 196, 34, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 2){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"拒绝";
        self.statusView1.backgroundColor = rgba(255, 233, 233, 1);
        self.statusView2.backgroundColor = rgba(255, 0, 0, 1);
        self.statusLabel.textColor = rgba(255, 0, 0, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 3){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"审核中";
        self.statusView1.backgroundColor = rgba(255, 244, 232, 1);
        self.statusView2.backgroundColor = rgba(255, 137, 0, 1);
        self.statusLabel.textColor = rgba(255, 137, 0, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 4){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"撤回";
        self.statusView1.backgroundColor = rgba(223, 223, 223, 1);
        self.statusView2.backgroundColor = rgba(90, 98, 112, 1);
        self.statusLabel.textColor = rgba(90, 98, 112, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 5){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"未提交";
        self.statusView1.backgroundColor = rgba(242, 241, 241, 1);
        self.statusView2.backgroundColor = rgba(184, 184, 184, 1);
        self.statusLabel.textColor = rgba(184, 184, 184, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 6){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"创建";
        self.statusView1.backgroundColor = rgba(242, 247, 255, 1);
        self.statusView2.backgroundColor = rgba(40, 120, 255, 1);
        self.statusLabel.textColor = rgba(40, 120, 255, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 7){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"删除";
        self.statusView1.backgroundColor = rgba(242, 241, 241, 1);
        self.statusView2.backgroundColor = rgba(184, 184, 184, 1);
        self.statusLabel.textColor = rgba(184, 184, 184, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 8){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"作废";
        self.statusView1.backgroundColor = rgba(242, 241, 241, 1);
        self.statusView2.backgroundColor = rgba(184, 184, 184, 1);
        self.statusLabel.textColor = rgba(184, 184, 184, 1);
    }else  if([GetHandleString(dataDic, @"examineStatus") integerValue] == 10){
        //        0待审核、1通过、2拒绝、3审核中 4:撤回 5 未提交 6 创建 7 已删除 8 作废 10 忽略 即未启用审批流
        self.statusLabel.text = @"忽略";
        self.statusView1.backgroundColor = rgba(242, 241, 241, 1);
        self.statusView2.backgroundColor = rgba(184, 184, 184, 1);
        self.statusLabel.textColor = rgba(184, 184, 184, 1);
    }
    if([[dataDic objectForKey:@"customerList"] isKindOfClass:[NSArray class]]){
        NSArray *array = [dataDic objectForKey:@"customerList"];
        NSMutableString *name = [NSMutableString string];
        for (NSInteger i = 0; i < array.count;i++) {
            if(i < array.count-1){
                [name appendString:[NSString stringWithFormat:@"%@,",GetHandleString(array[i], @"name")]];
            }else{
                [name appendString:GetHandleString(array[i], @"name")];
            }
        }
        self.userLabel.text = name;
    }else{
        self.userLabel.text = @"";
    }
    
    
    if([[dataDic objectForKey:@"customerList"] isKindOfClass:[NSArray class]]){
        NSMutableString *name = [NSMutableString string];
       NSArray *array = [dataDic objectForKey:@"customerList"];
        NSMutableArray *nameArray = [NSMutableArray array];
        for (NSInteger i = 0; i < array.count;i++) {
            if(i < array.count-1){
                [name appendString:[NSString stringWithFormat:@"%@,",GetHandleString(array[i], @"name")]];
            }else{
                [name appendString:GetHandleString(array[i], @"name")];
            }
            [nameArray addObject:GetHandleString(array[i], @"name")];
        }

        NSMutableAttributedString *attributedString2 = [[NSMutableAttributedString alloc]initWithString:name];

        NSMutableParagraphStyle *par = [[NSMutableParagraphStyle alloc]init];

        par.alignment = NSTextAlignmentRight;
        

        NSDictionary *dic1=@{NSParagraphStyleAttributeName : par,

        NSFontAttributeName : [UIFont systemFontOfSize:14],

        NSUnderlineStyleAttributeName : [NSNumber numberWithInteger:NSUnderlineStyleNone]

        };

        [attributedString2 setAttributes:dic1 range:NSMakeRange(0, name.length)];

        
        
        _userLabel.text = @"";
        _userLabel.attributedText = attributedString2;
        [_userLabel yb_addAttributeTapActionWithStrings:nameArray tapClicked:^(NSString *string, NSRange range, NSInteger index) {
            NSString *message = [NSString stringWithFormat:@"点击了“%@”字符\nrange: %@\nindex: %ld",string,NSStringFromRange(range),index];
            
            NSLog(@"message:%@",message);
            
            NSDictionary *user = array[index];
            if(_userInfoClickBlock){
                _userInfoClickBlock(GetHandleString(user, @"id"));
            }
       
        }];
        //设置是否有点击效果，默认是YES
        _userLabel.enabledTapEffect = NO;
        
//        计算label高度
        CGSize baseSize = CGSizeMake(ScreenWidth-132, CGFLOAT_MAX);
        CGSize labelsize  = [name
                            boundingRectWithSize:baseSize
                            options:NSStringDrawingUsesLineFragmentOrigin
                            attributes:dic1
                            context:nil].size;
        
        if(labelsize.height < 18){
            labelsize.height = 18;
        }
        
        self.labelHeight.constant = labelsize.height;
        _userLabel.isAttributedContent = YES;
        
    }else{
//        _userLabel.attributedText = nil;
//        _userLabel.text = @"";
//        
//        _userLabel.sd_layout
//        .widthIs(ScreenWidth-100)
//        .rightSpaceToView(self.contentView, 16)
//        .centerYEqualToView(_remindLabel)
//        .heightIs(18);
        
        self.labelHeight.constant = 18;
        
    }
    
    
    
    [self setupAutoHeightWithBottomView:_backView bottomMargin:12];
}


- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end

